<?php
include_once('../../app/connection.php');

if(isset($_POST['action']))
{
    $action = $_POST['action'];
    
    if($action == "check_mamh")
    {
        if(isset($_POST['mamh']))
        {
            $mamh = $_POST['mamh'];
            $sql = "SELECT * FROM monhoc WHERE MAMONHOC='".$mamh."'";
            $result = mysql_query($sql);
            if(mysql_num_rows($result) != 0)        
                echo '<span style="color:red"><i>'.$mamh.' đã tồn tại</i></span>';
            else if($mamh != '') echo '<span style="color:green"><i>'.$mamh.' chưa có</i></span>';
        }
    }
    
    if($action == "add_mh")
    {
        if(isset($_POST['mamh']))
        {
            $mamh = $_POST['mamh'];
            $tenmh = $_POST['tenmh'];
            $makhoa = $_POST['khoa'];
            $hocky = $_POST['hocky'];
            $tclt = $_POST['tclt'];
            $tcth = $_POST['tcth'];
            
            $sql = "INSERT INTO `monhoc`(MAMONHOC, TENMONHOC, TINCHILYTHUYET, TINCHITHUCHANH, HOCKY, MAKHOA, TRANGTHAI) VALUES 
                    ('$mamh','$tenmh','$tclt','$tcth','$hocky','$makhoa', 1)";
            $result = mysql_query($sql) or die("co loi");
            
            echo "Đã thêm ". $mamh;
        }
    }
}

?>